package com.agent.web.report;

import com.agent.entity.Dept;
import com.agent.entity.Report;
import com.agent.entity.TblCallSerial;
import com.agent.page.EasyuiPage;
import com.agent.service.IReportService;
import com.agent.util.DateUtil;
import com.agent.util.ResponseData;
import com.agent.vo.CustomKPIVO;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/report")
@Slf4j
public class ReportController {

    @Autowired
    IReportService reportService;

    @RequestMapping(value = "/searchSourceReport",method = RequestMethod.GET)
    @ResponseBody
    public EasyuiPage searchSourceReport(Integer page, Integer rows, String ringTime){
        EasyuiPage<Report> pages = new EasyuiPage<Report>();
        if(StringUtils.isEmpty(ringTime)){
            return pages;
        }
        try{
            Map<String ,String> maps = new HashMap<>();
            String[] split = ringTime.split(" - ");
            maps.put("beingTime",split[0]);
            maps.put("endTime",split[1]);
            List<Report> reportList = reportService.searchSourceReport(maps);
            pages.setRows(reportList);
            pages.setTotal(reportList.size());
        }catch (Exception e){
            log.error("com.agent.web.report.ReportController.searchSourceReport error |",e);
        }
        return pages;
    }

    @RequestMapping(value = "/searchDeptReport",method = RequestMethod.GET)
    @ResponseBody
    public EasyuiPage searchDeptReport(Integer page, Integer rows, String ringTime){
        EasyuiPage<Report> pages = new EasyuiPage<Report>();
        if(StringUtils.isEmpty(ringTime)){
            return pages;
        }
        try{
            Map<String ,String> maps = new HashMap<>();
            String[] split = ringTime.split(" - ");
            maps.put("beingTime",split[0]);
            maps.put("endTime",split[1]);
            List<Report> reportList = reportService.searchDeptReport(page,rows,maps);
            pages.setRows(reportList);
            pages.setTotal(reportList.size());
        }catch (Exception e){
            log.error("com.agent.web.report.ReportController.searchDeptReport error |",e);
        }
        return pages;
    }

    @RequestMapping(value = "/searchCustomKPI",method = RequestMethod.GET)
    @ResponseBody
    public EasyuiPage searchCustomKPI(Integer page, Integer rows, String ringTime){
        EasyuiPage<CustomKPIVO> pages = new EasyuiPage<CustomKPIVO>();
        if(StringUtils.isEmpty(ringTime)){
            return pages;
        }
        try{
            Map<String ,String> maps = new HashMap<>();
            String[] split = ringTime.split(" - ");
            maps.put("beingTime",split[0]);
            maps.put("endTime",split[1]);
            List<CustomKPIVO> reportList = reportService.searchCustomKPI(page,rows,maps);
            pages.setRows(reportList);
            pages.setTotal(reportList.size());
        }catch (Exception e){
            log.error("com.agent.web.report.ReportController.searchCustomKPI error |",e);
        }
        return pages;
    }
}
